import 'package:FlutterDemo/widget/customerviews/test_page_accounts.dart';
import 'package:FlutterDemo/widget/customerviews/test_page_book.dart';
import 'package:FlutterDemo/widget/customerviews/test_page_home.dart';
import 'package:flutter/material.dart';

class SampleBottomNavigationBarWidget extends StatelessWidget {
  const SampleBottomNavigationBarWidget({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return _SampleBottomNavigationBarWidget();
  }
}

class _SampleBottomNavigationBarWidget extends StatefulWidget {
  const _SampleBottomNavigationBarWidget({Key? key}) : super(key: key);

  @override
  __SampleBottomNavigationBarWidgetState createState() => __SampleBottomNavigationBarWidgetState();
}

class __SampleBottomNavigationBarWidgetState extends State<_SampleBottomNavigationBarWidget> {
  int _currentIndex = 0;
  Widget _currentBody = TestHomePage();

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: Text("底部弹窗测试"),
        ),
        body: _currentBody,
        bottomNavigationBar: BottomNavigationBar(
          onTap: (index) {
            _onTap(index);
          },
          type: BottomNavigationBarType.shifting,
          selectedItemColor: Theme.of(context).primaryColor,
          unselectedItemColor: Colors.black,
          currentIndex: _currentIndex,
          items: [
            BottomNavigationBarItem(title: Text('首页'), icon: Icon(Icons.home)),
            BottomNavigationBarItem(title: Text('书籍'), icon: Icon(Icons.book)),
            BottomNavigationBarItem(title: Text('我的'), icon: Icon(Icons.verified_user))
          ],
        ),
      ),
    );
  }

  _onTap(int index) {
    switch (index) {
      case 0:
        _currentBody = TestHomePage();
        break;
      case 1:
        _currentBody = TestBookPage();
        break;
        _currentBody = TestAccountsPage();
      case 2:
        break;
    }
    setState(() {
      _currentIndex = index;
    });
  }
}
